
/**
* @module parse-message
* @author: Hjava
* @description: 解析消息模块
* @since: 2018-07-23 12:34:54
*/
Object.defineProperty(exports, "__esModule", { value: true });
var message_1 = __webpack_require__(/*! _models/message */ "./src/extra/models/message.ts");
var cancel_message_1 = __webpack_require__(/*! _models/cancel-message */ "./src/extra/models/cancel-message.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var long_1 = __webpack_require__(/*! _util/long */ "./src/core/utils/long.ts");
function msgIdToString(msgId) {
    return (!msgId || msgId === '') ? '' : long_1.default.fromValue(msgId, true).value();
}
function parse(messageDatum) {
    switch (messageDatum.messageReceivedType) {
        case constant_1.MESSAGE_RECEIVED_TYPE.CHAT_MESSAGE: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, fromUid = messageDatum.fromUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, receipt = messageDatum.receipt, seqId = messageDatum.seqId, toUid = messageDatum.toUid, type = messageDatum.type, status = messageDatum.status, isLocal = messageDatum.isLocal, toAppId = messageDatum.toAppId;
            return new message_1.ChatMessage({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                receipt: receipt,
                seqId: seqId,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                type: type,
                status: status,
                message: message,
                isLocal: isLocal,
                toAppId: toAppId
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CHAT_MESSAGE2: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, fromUid = messageDatum.fromUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, receipt = messageDatum.receipt, seqId = messageDatum.seqId, toUid = messageDatum.toUid, type = messageDatum.type, status = messageDatum.status, isLocal = messageDatum.isLocal, toAppId = messageDatum.toAppId, sid = messageDatum.sid;
            return new message_1.ChatMessage2({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                receipt: receipt,
                seqId: seqId,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                type: type,
                status: status,
                message: message,
                isLocal: isLocal,
                toAppId: toAppId,
                sid: sid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.GROUP_MESSAGE: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, fromUid = messageDatum.fromUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, receipt = messageDatum.receipt, seqId = messageDatum.seqId, toGuid = messageDatum.toGuid, type = messageDatum.type, status = messageDatum.status, isLocal = messageDatum.isLocal, fromPubId = messageDatum.fromPubId, fromPubName = messageDatum.fromPubName, groupName = messageDatum.groupName;
            return new message_1.GroupChatMessage({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                receipt: receipt,
                seqId: seqId,
                from: fromUid,
                to: toGuid,
                belongTo: toGuid,
                type: type,
                status: status,
                message: message,
                isLocal: isLocal,
                fromPubId: fromPubId,
                fromPubName: fromPubName,
                groupName: groupName
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_CHAT_MESSAGE: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce;
            return new cancel_message_1.ChatCancelMessage({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                extension: extension,
                channelId: channel,
                isForce: isforce
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_CHAT_MESSAGE2: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce, sid = messageDatum.sid;
            return new cancel_message_1.ChatCancelMessage2({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                extension: extension,
                channelId: channel,
                isForce: isforce,
                sid: sid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_GROUP_MESSAGE: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toGuid = messageDatum.toGuid, fromName = messageDatum.fromName, groupName = messageDatum.groupName, cts = messageDatum.cts, msgId = messageDatum.msgId, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce, adminUid = messageDatum.adminUid;
            return new cancel_message_1.GroupChatCancelMessage({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toGuid,
                belongTo: toGuid,
                fromName: fromName,
                groupName: groupName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                channelId: channel,
                isForce: isforce,
                adminUid: adminUid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.PUB_MESSAGE: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, fromUid = messageDatum.fromUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, toUid = messageDatum.toUid, direction = messageDatum.direction, type = messageDatum.type, status = messageDatum.status, pubTTMessage = messageDatum.pubTTMessage, isLocal = messageDatum.isLocal, sessionSeqId = messageDatum.sessionSeqId, compatible = messageDatum.compatible;
            // 处理 PUB 透传消息
            if (pubTTMessage) {
                return new message_1.PubTTMessage({
                    channelId: channel,
                    deviceType: deviceType,
                    fromName: fromName,
                    uuid: msgUuid,
                    time: parseInt(cts),
                    mid: msgIdToString(msgId),
                    extension: extension,
                    from: fromUid,
                    to: toUid,
                    toAppId: 0,
                    belongTo: direction === 1 ? toUid : fromUid,
                    type: type,
                    direction: direction,
                    status: status,
                    message: message,
                    sessionSeqId: sessionSeqId,
                    compatible: compatible
                });
            }
            return new message_1.PubChatMessage({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                from: fromUid,
                to: toUid,
                toAppId: 0,
                belongTo: direction === 1 ? toUid : fromUid,
                type: type,
                direction: direction,
                status: status,
                message: message,
                isLocal: isLocal,
                sessionSeqId: sessionSeqId,
                compatible: compatible
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.PUB_MESSAGE2: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, fromUid = messageDatum.fromUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, toUid = messageDatum.toUid, direction = messageDatum.direction, type = messageDatum.type, status = messageDatum.status, pubTTMessage = messageDatum.pubTTMessage, isLocal = messageDatum.isLocal, sessionSeqId = messageDatum.sessionSeqId, compatible = messageDatum.compatible, sid = messageDatum.sid;
            // 处理 PUB 透传消息
            if (pubTTMessage) {
                return new message_1.PubTTMessage({
                    channelId: channel,
                    deviceType: deviceType,
                    fromName: fromName,
                    uuid: msgUuid,
                    time: parseInt(cts),
                    mid: msgIdToString(msgId),
                    extension: extension,
                    from: fromUid,
                    to: toUid,
                    toAppId: 0,
                    belongTo: direction === 1 ? toUid : fromUid,
                    type: type,
                    direction: direction,
                    status: status,
                    message: message,
                    sessionSeqId: sessionSeqId,
                    compatible: compatible,
                });
            }
            return new message_1.PubChatMessage2({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                from: fromUid,
                to: toUid,
                toAppId: 0,
                belongTo: direction === 1 ? toUid : fromUid,
                type: type,
                direction: direction,
                status: status,
                message: message,
                isLocal: isLocal,
                sessionSeqId: sessionSeqId,
                compatible: compatible,
                sid: sid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.KEFU_MESSAGE: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, senderUid = messageDatum.senderUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, pubUid = messageDatum.pubUid, receiverUid = messageDatum.receiverUid, direction = messageDatum.direction, type = messageDatum.type, status = messageDatum.status, isLocal = messageDatum.isLocal;
            return new message_1.CSChatMessage({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                from: senderUid,
                to: receiverUid,
                toAppId: 0,
                belongTo: pubUid + "_" + (direction === 1 ? receiverUid : senderUid),
                pubId: pubUid,
                peerUid: direction === 1 ? receiverUid : senderUid,
                type: type,
                direction: direction,
                status: status,
                message: message,
                isLocal: isLocal
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.KEFU_MESSAGE2: {
            var appid = messageDatum.appid, channel = messageDatum.channel, cts = messageDatum.cts, deviceType = messageDatum.deviceType, extension = messageDatum.extension, fromName = messageDatum.fromName, senderUid = messageDatum.senderUid, message = messageDatum.message, msgId = messageDatum.msgId, msgUuid = messageDatum.msgUuid, pubUid = messageDatum.pubUid, receiverUid = messageDatum.receiverUid, direction = messageDatum.direction, type = messageDatum.type, status = messageDatum.status, isLocal = messageDatum.isLocal, sid = messageDatum.sid;
            return new message_1.CSChatMessage2({
                appId: appid,
                channelId: channel,
                deviceType: deviceType,
                fromName: fromName,
                uuid: msgUuid,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                extension: extension,
                from: senderUid,
                to: receiverUid,
                toAppId: 0,
                belongTo: pubUid + "_" + (direction === 1 ? receiverUid : senderUid),
                pubId: pubUid,
                peerUid: direction === 1 ? receiverUid : senderUid,
                type: type,
                direction: direction,
                status: status,
                message: message,
                isLocal: isLocal,
                sid: sid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_PUB_MESSAGE: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, direction = messageDatum.direction, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce;
            return new cancel_message_1.PubChatCancelMessage({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                direction: direction,
                extension: extension,
                channelId: channel,
                isForce: isforce
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_PUB_MESSAGE2: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, direction = messageDatum.direction, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce, sid = messageDatum.sid;
            return new cancel_message_1.PubChatCancelMessage2({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: (!fromUid || fromUid === userData_1.default.get('uid')) ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                direction: direction,
                extension: extension,
                channelId: channel,
                isForce: isforce,
                sid: sid
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_PUB_KF_MESSAGE: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, pubUid = messageDatum.pubUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, direction = messageDatum.direction, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce;
            return new cancel_message_1.PubChatCancelKFMessage({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: pubUid + "_" + (direction === 1 ? toUid : fromUid),
                pubId: pubUid,
                peerUid: direction === 1 ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                direction: direction,
                extension: extension,
                channelId: channel,
                isForce: isforce
            });
        }
        case constant_1.MESSAGE_RECEIVED_TYPE.CANCEL_PUB_KF_MESSAGE2: {
            var deviceType = messageDatum.deviceType, msgUuid = messageDatum.msgUuid, fromUid = messageDatum.fromUid, toUid = messageDatum.toUid, pubUid = messageDatum.pubUid, fromName = messageDatum.fromName, cts = messageDatum.cts, msgId = messageDatum.msgId, toAppId = messageDatum.toAppId, direction = messageDatum.direction, extension = messageDatum.extension, channel = messageDatum.channel, isforce = messageDatum.isforce, sid = messageDatum.sid;
            return new cancel_message_1.PubChatCancelKFMessage2({
                appId: userData_1.default.get('appId'),
                deviceType: deviceType,
                uuid: msgUuid,
                from: fromUid,
                to: toUid,
                belongTo: pubUid + "_" + (direction === 1 ? toUid : fromUid),
                pubId: pubUid,
                peerUid: direction === 1 ? toUid : fromUid,
                fromName: fromName,
                time: parseInt(cts),
                mid: msgIdToString(msgId),
                toAppId: toAppId,
                direction: direction,
                extension: extension,
                channelId: channel,
                isForce: isforce,
                sid: sid
            });
        }
        default: {
            return null;
        }
    }
}
exports.default = parse;


//# sourceURL=webpack://MTDX/./src/extra/utils/parse-message.ts?